<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>主页</title>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="${pageContext.request.contextPath}/js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <c:if test="${sessionScope.user.flag}">
        <a style="float:left;margin: 5px" class="btn btn-primary"
           href="${pageContext.request.contextPath}/User/reLogin">注销</a>
    </c:if>
    <c:if test="${!sessionScope.user.flag}">
        <a style="float:left;margin: 5px" class="btn btn-primary"
           href="${pageContext.request.contextPath}/User/reLogin">注销</a>
    </c:if>

    <img style="float:right" src="${pageContext.request.contextPath}/headImg/${sessionScope.user.path}"
         class="img-thumbnail" width="150" height="150">

    <h2 style="text-align: center;">XX博客</h2>
    <h3 style="text-align: center;">欢迎你,${sessionScope.user.username}</h3>
    <p style="text-align: center;" class="bg-info">---</p>
    <table border="1" class="table table-bordered table-hover">
        <tr>
            <form action="${pageContext.request.contextPath}/UserBlog/findBlogPage"
                  method="post">
                <td>
                    <textarea class="form-control" rows="1" name="findBlog" placeholder="请在此输入搜索关键字"></textarea>
                </td>
                <td>
                    <input style="margin:5px" class="btn btn btn-primary" type="submit" value="搜索">
                </td>
            </form>
        </tr>
    </table>
    <p style="text-align: center;" class="bg-info">---</p>
    <c:if test="${sessionScope.user.flag}">
        <!-- 出错显示的信息框 -->
        <c:if test="${requestScope.managerLogin_msg!=null}">
            <div class="alert alert-warning alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert">
                    <span>&times;</span></button>
                <strong>${requestScope.managerLogin_msg}</strong>
            </div>
        </c:if>
        <a style="align :center;margin: 5px" class="btn btn-primary"
           href="${pageContext.request.contextPath}/User/managerLogin">管理员界面</a>
        <a style="align :center;margin: 5px" class="btn btn-primary"
           href="${pageContext.request.contextPath}/Column/columnPage">我也要写博客</a>
        <a style="align :center;margin: 5px" class="btn btn-primary"
           href="${pageContext.request.contextPath}/UserBlog/findUserBlog">进入我的博客</a>
        <a style="align :center;margin: 5px" class="btn btn-primary"
           href="${pageContext.request.contextPath}/modifyPassword.jsp">修改密码</a>
    </c:if>
    <a style="align :center;margin: 5px" class="btn btn-primary"
       href="${pageContext.request.contextPath}/UserLike/myLike">我的收藏</a>
    <c:if test="${requestScope.like_flag!=null&&requestScope.like_flag}">
        <p style="text-align: center;" class="bg-info">---</p>
        <%--用表格展示下用户的收藏--%>
        <div class="list-group">
            <li class="list-group-item active">
                我的收藏
            </li>
            <c:forEach items="${requestScope.userLikeBlog}" var="blog" varStatus="s">
                <a href="${pageContext.request.contextPath}/UserBlog/Blog?id=${blog.id}"
                   class="list-group-item">${s.count}.${blog.title}</a>
            </c:forEach>
        </div>
    </c:if>
    <p style="text-align: center;" class="bg-info">---</p>


    <%--展示专栏--%>
    <h4 style="text-align: center;">专栏区</h4>
    <nav aria-label="...">
        <ul class="pager">
            <a style="float:left;margin: 5px" class="btn btn-primary"
               href="${pageContext.request.contextPath}/UserBlog/findBlogByPage">返回</a>
            <li>
                <a href="${pageContext.request.contextPath}/UserBlog/findBlogByPage?ccurrentPage=${requestScope.columnPageBean.currentPage-1}&crows=5&columnId=${requestScope.columnId}">Previous</a>
            </li>

            <c:if test="${requestScope.columnPageBean.totalCount!=0}">
                <c:forEach items="${requestScope.columnPageBean.list}" var="column" varStatus="s">
                    <a style="align :center;margin: 5px" class="btn btn-primary"
                       href="${pageContext.request.contextPath}/UserBlog/findBlogByPage?columnId=${column.id}">
                        <h4>${column.name}</h4>
                    </a>
                </c:forEach>
            </c:if>

            <c:if test="${requestScope.columnPageBean.totalCount==0}">
                该专栏暂时没有子专栏哦
            </c:if>


            <li>
                <a href="${pageContext.request.contextPath}/UserBlog/findBlogByPage?ccurrentPage=${requestScope.columnPageBean.currentPage+1}&crows=5&columnId=${requestScope.columnId}">Next</a>
            </li>
        </ul>
    </nav>

    <p style="text-align: center;" class="bg-info">---</p>
    <%--展示用户的文章--%>
    <table border="1" class="table table-bordered table-hover">
        <c:forEach items="${requestScope.blogPageBean.list}" var="blog" varStatus="s">
            <a href="${pageContext.request.contextPath}/UserBlog/Blog?id=${blog.id}"><h4>${blog.title}</h4></a>
            <blockquote>
                <c:if test="${blog.content.length()>=20}">
                    <p>${blog.content.substring(0,20)}...</p>
                </c:if>
                <c:if test="${blog.content.length()<20}">
                    <p>${blog.content}</p>
                </c:if>
            </blockquote>
        </c:forEach>
    </table>


    <%--下面这里是分页的数据--%>
    <div>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <%--这个li就是代表上一页的了--%>
                <c:if test="${requestScope.blogPageBean.currentPage==1}">
                <li class="disabled">
                        <%--这里是一个禁用,但页码为1的时候不让用--%>
                    </c:if>
                    <c:if test="${requestScope.blogPageBean.currentPage!=1}">
                <li>
                    </c:if>
                    <a href="${pageContext.request.contextPath}/UserBlog/findBlogByPage?currentPage=${requestScope.blogPageBean.currentPage-1}&rows=5&columnId=${requestScope.columnId}"
                       aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>


                <c:forEach begin="1" end="${requestScope.blogPageBean.totalPage}" var="i">
                    <%--上面这个显示的是激活状态
                    下面显示的是未激活状态 --%>
                    <c:if test="${requestScope.blogPageBean.currentPage==i}">
                        <li class="active"><a
                                href="${pageContext.request.contextPath}/UserBlog/findBlogByPage?currentPage=${i}&rows=5&columnId=${requestScope.columnId}">${i}</a>
                        </li>
                    </c:if>
                    <c:if test="${requestScope.blogPageBean.currentPage!=i}">
                        <li>
                            <a href="${pageContext.request.contextPath}/UserBlog/findBlogByPage?currentPage=${i}&rows=5&columnId=${requestScope.columnId}">${i}</a>
                        </li>
                    </c:if>
                </c:forEach>

                <c:if test="${requestScope.blogPageBean.currentPage==requestScope.blogPageBean.totalPage}">
                <li class="disabled">
                    </c:if>
                    <c:if test="${requestScope.blogPageBean.currentPage!=requestScope.blogPageBean.totalPage}">
                <li>
                    </c:if>
                    <a href="${pageContext.request.contextPath}/UserBlog/findBlogByPage?currentPage=${requestScope.blogPageBean.currentPage+1}&rows=5&columnId=${requestScope.columnId}"
                       aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>

                <span style="font-size: 25px;margin: 5px">
                共${requestScope.blogPageBean.totalCount}条记录,共${requestScope.blogPageBean.totalPage}页
                </span>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>
